home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AOCE Sample Code / PowerTalk Access Modules / Sample PMSAM / PMSAM Framework / RoboSamSlot / CLinkedList.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-28  |  1.7 KB  |  91 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        CLinkedList.h
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Written by:    Tim Harnett
  7.  
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>     2/14/95    TMH        tweak
  13.          <1>      2/6/95    TMH        new
  14.                   2/6/95    TMH        xxx put comment here xxx
  15.  
  16.     To Do:
  17. */
  18.  
  19. #ifndef __CLinkedList__
  20. #define __CLinkedList__
  21.  
  22.  
  23. //----------------------------
  24. //        C L i n k
  25. //----------------------------
  26.  
  27.  
  28. class CLink {
  29.     friend class CLinkedList;
  30.     friend class CLinkedListIterator;
  31. public:
  32.     CLink() {fLink=0;};
  33. private:
  34.     CLink*    fLink;
  35. };
  36.  
  37.  
  38.  
  39. //---------------------------
  40. //    C L i n k e d L i s t
  41. //--------------------------
  42.  
  43.  
  44. class CLinkedList {
  45.     friend class CLinkedListIterator;
  46. public:
  47.     CLinkedList() {fHead=0; fTail=0; fNItems=0;};
  48.     
  49.     CLink*    UnlinkHead();
  50.     void    LinkTail(CLink* item);
  51.     
  52.     CLink*    Head() { return fHead; };
  53.     CLink*    Tail() { return fTail; };
  54.     long    Count() { return fNItems; };
  55.     
  56. private:
  57.     CLink*    fHead;
  58.     CLink*    fTail;
  59.     long    fNItems;
  60.  
  61. };
  62.  
  63.  
  64. //-----------------------------------------
  65. //    C L i n k e d L i s t I t e r a t o r
  66. //------------------------------------------
  67.  
  68.  
  69. class CLinkedListIterator {
  70. public:
  71.             CLinkedListIterator(CLinkedList* linkedList) { fLinkedList = linkedList; fCurrItem = 0; fPrevItem = 0;  fNextItem = 0;};
  72.  
  73.     CLink*    FirstItem() { fPrevItem = 0; fCurrItem = fLinkedList->Head(); if(fCurrItem!= 0) fNextItem = fCurrItem->fLink; return fCurrItem;  }
  74.     Boolean    More()        { return fCurrItem !=0; }
  75.     CLink*    NextItem()    { fPrevItem = fCurrItem; fCurrItem = fNextItem; if( fCurrItem!=0) fNextItem = fCurrItem->fLink; return fCurrItem; };
  76.     
  77.     void    UnlinkCurrentItem();
  78.  
  79.     CLinkedList*    fLinkedList;
  80.     CLink*            fCurrItem;
  81.     CLink*            fPrevItem;
  82.     CLink*            fNextItem;
  83.     
  84.  
  85.  
  86. };
  87.  
  88.  
  89. #endif      __CLinkedList__
  90.  
  91.